<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>供应商管理</title>
</head>
<body>
<div ng-app="myApp" ng-controller="SupplierCtrl">

         <label>注:如果新增商家所属的供应商分组已存在，则直接选择，没有则在输入框中输入供应商编码和供应商分组</label>
        <ui-form key="supplierAdd" column="2">
            <ui-form-input name="code" label="供应商编码:"></ui-form-input>
            <ui-form-input name="name" label="供货商名称:"></ui-form-input>
            <ui-form-select name="state" label="激活状态:" value="${supplier.state}">
                <option value="0">否</option>
                <option value="1">是</option>
            </ui-form-select>
            <ui-form-select name="isCombined" label="是否组包:" value="${supplier.isCombined}">
                <option value="0">否</option>
                <option value="1">是</option>
            </ui-form-select>
            <ui-form-select-remote label="供货商分组" url="system/supplier/listgroups" value-name="id" text-name="name" name="groupId"></ui-form-select-remote>
            <ui-form-input name="groupCode" label="供货商分组编码:" ></ui-form-input>
            <ui-form-input name="groupName" label="供货商分组名称:" ></ui-form-input>
        </ui-form>
</div>
<script>
    angular.module('myApp', ['ui.form']);
    angular.module('myApp').controller('SupplierCtrl', function ($scope) {
        $scope.gggg="5"
        $scope.$on('ui.form.submit',function (event,param) {
            $.ajax({
                url:"system/supplier/add",
                type:"post",
                data:param
            }).done(function (result) {
                if(result.code=='0000'){
                    toastr.success(result.data);
                    setTimeout(function () {
                        window.location.href="system/supplier/index.htm";
                    },1500);
                }else{
                    toastr.error(result.msg);
                }
            }).fail(function (err) {
                
            });
        })
    });
    $(document).ready(function () {
        $("select[name='groupId']").bind('change',function (event) {
            console.info(event);
            var value=event.currentTarget.value;
            if(value!=undefined && value!=""){
                $("input[name='groupCode']").attr("readonly",true);
                $("input[name='groupName']").attr("readonly",true);

            }else{
                $("input[name='groupCode']").attr("readonly",false);
                $("input[name='groupName']").attr("readonly",false);
            }

        })
    })

    $(document).ready(function () {
        $("input[name='groupCode']").bind('change',function (event) {
            console.info(event);
            var value=event.currentTarget.value;
            if(value!=undefined&&value!=""){
                $("select[name='groupId']").attr("readonly",true);
            }else{
                $("select[name='groupId']").attr("readonly",false);
            }

        })

    })

    $(document).ready(function () {
        $("input[name='groupName']").bind('change',function (event) {
            console.info(event);
            var value=event.currentTarget.value;
            if(value!=undefined&&value!=""){
                $("select[name='groupId']").attr("readonly",true);
            }else{
                $("select[name='groupId']").attr("readonly",false);
            }

        })

    })
</script>
</body>
</html>
